package cn.iocoder.yudao.module.design.controller.admin.reform;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.design.controller.admin.reform.vo.ReformCreateReqVO;
import cn.iocoder.yudao.module.design.controller.admin.reform.vo.ReformUpdateReqVO;
import cn.iocoder.yudao.module.design.service.reform.ReformBusinessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 项目整改单/业务模块")
@RestController
@RequestMapping("/design/reform/business")
@Validated
public class ReformBusinessController {

    @Resource
    private ReformBusinessService reformService;


    @PostMapping("/create")
    @Operation(summary = "创建项目整改单")
    @PreAuthorize("@ss.hasPermission('design:reform:create')")
    public CommonResult<Integer> createReform(@Valid @RequestBody ReformCreateReqVO createReqVO) {
        return success(reformService.createReform(createReqVO));
    }

    @PutMapping("/updateStatus")
    @Operation(summary = "更新项目整改单状态")
    @PreAuthorize("@ss.hasPermission('design:reform:update')")
    public CommonResult<Boolean> updateReformStatus(@Valid @RequestBody ReformUpdateReqVO updateReqVO) {
        reformService.updateReformStatus(updateReqVO.getId(),updateReqVO.getStatusCd(),updateReqVO.getConfirmUrl());
        return success(true);
    }

    @PostMapping("/updateReform")
    @Operation(summary = "项目整改单内容修改")
    @PreAuthorize("@ss.hasPermission('design:reform:update')")
    public CommonResult<Boolean> updateReform(@Valid @RequestBody ReformUpdateReqVO updateReqVO) {
        reformService.updateReform(updateReqVO);
        return success(true);
    }

    @PutMapping("/confirmReform")
    @Operation(summary = "项目整改单确认")
    @PreAuthorize("@ss.hasPermission('design:reform:update')")
    public CommonResult<Boolean> confirmReform(@Valid @RequestBody ReformUpdateReqVO updateReqVO) {
        reformService.confirmReform(updateReqVO.getId(),updateReqVO.getStatusCd(),updateReqVO.getConfirmUrl());
        return success(true);
    }


}
